var app = getApp();
const util = require('../../utils/util.js');
// pages/order/downline.js
Page({
  data:{
    itemData:{},
    userId:0,
    paytype:'weixin',//0线下1微信
    remark:'',
    cartId:0,
    addrId:0,//收货地址//测试--
    btnDisabled:false,
    productData: [],
    address:{},
    total:0,
    vprice:0,
    vid:0,
    addemt:1,
    vou:[]
  },
  onShow:function(){
    var data = this.data.payData;
    var that = this;
    var data = { data: data, user_id: app.globalData.userInfo.id };
    util.commonRequest("index/Order/index", 'post', data, function (res) {
      if (res.data.code == 200){
        that.setData({
          productData:res.data.data.data,
          total: res.data.data.total,
          address: res.data.data.address
        })
      }
    });
  },
  onLoad:function(options){
    var data = options.strId;
    this.setData({
      payData:data
    })
  },
  gotoAddress:function(){
    wx.navigateTo({
      url: '../address/index?ista=1',
    })
  },
//微信支付
  createProductOrderByWX:function(e){
    var data = this.data.payData;
    var that = this;
    let address = this.data.address;
    let addDetail = address.province+address.city+address.district+address.address;
    var data = { data: data, user_id: app.globalData.userInfo.id, contact: address.contact, phone: address.phone, address: addDetail};
    util.commonRequest("index/Order/pay", 'post', data, function (res) {
       if (res.data.code == 200){
         wx.showToast({
           title: res.data.msg,
         })
       }else{
         wx.showToast({
           title: res.data.msg,
           icon:'none'
         })
       }
    });
  },
  wxpay: function (para) {
    // var res = JSON.parse(para.data);
    // wx.requestPayment({
    //   appId: res.appId,
    //   timeStamp: res.timeStamp,
    //   nonceStr: res.nonceStr,
    //   package: res.package,
    //   signType: 'MD5',
    //   paySign: res.paySign,
    //   success: function (res) {
    //     wx.showToast({
    //       title: '支付成功'
    //     });
    //     console.log(res);
    //   },
    //   fail: function (res) {
    //      wx.showToast({
    //        icon:"loading",
    //        title: '支付失败',
    //      })
    //   }
    // })
  }
});